package com.zmx.user.repository;

import com.zmx.common.common.repository.BaseRepository;
import com.zmx.user.entity.MemberReceiver;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
@author zhaomxr
*/
public interface MemberReceiverRepository extends BaseRepository<MemberReceiver>{

    @Query(value = "select * from member_receiver where member_id = ?1 order by create_date desc",nativeQuery = true)
    List<MemberReceiver> getByMemberId(Long memberId);


    @Query(value = "select * from member_receiver where is_default = 1 and member_id = ?1 limit 1",nativeQuery = true)
    MemberReceiver getReceiverDefault(Long memberId);

    @Modifying
    @Query(value = "update member_receiver set is_default = 0 where member_id = ?1", nativeQuery = true)
    void updateReceiverNoDefault(Long memberId);
}
